package com.ohc.leetcode.数组;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * 2022年5月16日09:47:46
 */
public class 救生艇881 {
    public static int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int sum = 0;
        int left = 0; // 最轻
        int right = people.length - 1; // 最重
        while (left <= right) {
            if (people[left] + people[right] <= limit) {
                left++;
            }
            right--;
            sum++;
        }
        return sum;
    }

    public static void main(String[] args) {
//        3,2,2,1  3
//        1 2 2 3   limit= 3
        int[] arr = {5, 4, 3, 3};
        int i = numRescueBoats(arr, 5);
        System.out.println("i = " + i);
    }
}
